<?php

declare(strict_types=1);

namespace sheep\library\install\provider;

use sheep\library\install\InstallManager;
use think\console\Output;

class Console
{

    protected $manager = null;

    protected $output = null;

    public function __construct(InstallManager $manager = null, Output $output = null)
    {
        $this->manager = $manager;
        $this->output = $output;
    }


    public function outputIntro($msg = 'SHEEP ADMIN INSTALLATION')
    {
        $this->output->writeln("**********************************************************************");
        $this->output->writeln("*********************** " . $msg . " *********************");
        $this->output->writeln("**********************************************************************");
        $this->output->writeln("");
    }


    /**
     * 模块开始
     */
    public function moduleStart($message)
    {
        $this->output->newLine();
        $this->output->writeln($message);
        $this->output->writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
    }

    /**
     * 模块结束
     */
    public function moduleEnd($message)
    {
        $this->output->newLine();
        $this->output->writeln($message);
        $this->output->writeln('=============================================================');
        $this->output->newLine();
    }


    /**
     * 检测环境输出
     */
    public function envOutput($checkItem)
    {
        foreach ($checkItem as $key => $item) {
            if (!$item['error']) {
                $this->output->writeln('[ok] ' . $item['msg']);
            } else if ($item['error'] == 1) {
                $this->output->error('[no] ' . $item['msg']);
            } else if ($item['error'] == 2) {
                $this->output->warning('[warning] ' . $item['msg']);
            } 
        }

        return true;
    }


    public function outputOutro($msg = 'SHEEP ADMIN INSTALL SUCCEEDED')
    {
        $this->output->writeln("");
        $this->output->writeln("**********************************************************************");
        $this->output->writeln("******************** " . $msg . " *******************");
        $this->output->writeln("**********************************************************************");
    }

    /**
     * 代理 output 方法
     */
    public function __call($funcname, $arguments)
    {
        return $this->output->{$funcname}(...$arguments);
    }
}
